﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WPF.DazzleUI.Controls;

namespace Demo
{
    /// <summary>
    /// ColorPicker.xaml 的交互逻辑
    /// </summary>
    public partial class ColorPicker : DazzleWindow
    {
        public ColorPicker()
        {
            InitializeComponent();
            
        }
        public override void EndInit()
        {
            a.ValueChanged +=new RoutedPropertyChangedEventHandler<double>(a_ValueChanged);
            r.ValueChanged +=new RoutedPropertyChangedEventHandler<double>(r_ValueChanged);
            g.ValueChanged +=new RoutedPropertyChangedEventHandler<double>(g_ValueChanged);
            b.ValueChanged +=new RoutedPropertyChangedEventHandler<double>(b_ValueChanged);


            base.EndInit();
        }

        private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            //更新颜色(Color.FromArgb((byte)a.Value, (byte)r.Value, (byte)g.Value, (byte)b.Value));
            //SelectColor = Color.FromArgb((byte)a.Value, (byte)r.Value, (byte)g.Value, (byte)b.Value);
            //this.DialogResult = true;
        }

        public Color SelectColor { get; set; }

        private void a_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            
            SelectColor = Color.FromArgb((byte)a.Value, (byte)r.Value, (byte)g.Value, (byte)b.Value);
            ColorChangeEvent(SelectColor);
            ColorSee.Fill = new SolidColorBrush(SelectColor);
        }

        private void r_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            SelectColor = Color.FromArgb((byte)a.Value, (byte)r.Value, (byte)g.Value, (byte)b.Value);
            ColorChangeEvent(SelectColor);
            ColorSee.Fill = new SolidColorBrush(SelectColor);
        }

        private void g_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            SelectColor = Color.FromArgb((byte)a.Value, (byte)r.Value, (byte)g.Value, (byte)b.Value);
            ColorChangeEvent(SelectColor);
            ColorSee.Fill = new SolidColorBrush(SelectColor);
        }

        private void b_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            SelectColor = Color.FromArgb((byte)a.Value, (byte)r.Value, (byte)g.Value, (byte)b.Value);
            ColorChangeEvent(SelectColor);
            ColorSee.Fill = new SolidColorBrush(SelectColor);
        }

        public event Action<Color> ColorChangeEvent;
    }
}
